const hre = require('hardhat');

// 使用: TX=0x... npx hardhat run scripts/debug-tx.js --network xlayerTestnet
// 默认使用提供的 faucet 交易哈希
const TX = process.env.TX || '0xd46f0d73e1eefd4fb403327941258bb0c511a349d95e3cda87d896688510676c';

async function main(){
  const net = await hre.ethers.provider.getNetwork();
  const latest = await hre.ethers.provider.getBlockNumber();
  console.log('Network chainId:', net.chainId.toString());
  console.log('Latest block:', latest);
  console.log('Query tx:', TX);
  const tx = await hre.ethers.provider.getTransaction(TX);
  console.log('Tx object:', tx);
  const receipt = await hre.ethers.provider.getTransactionReceipt(TX).catch(()=>null);
  console.log('Receipt:', receipt);
  if(receipt){
    const block = await hre.ethers.provider.getBlock(receipt.blockNumber);
    console.log('Tx Block number:', receipt.blockNumber);
    console.log('Tx Block timestamp:', block?.timestamp);
  }
}

main().catch(e=>{console.error(e);process.exit(1);});
